﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>2011-12-21 15:46:14Z</CreationDate>
</File>
*/
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Xml;
using System.Xml.Linq;

namespace Outcoder.Configuration
{
	/// <summary>
	/// This class allows access to the appSettings element 
	/// of the App.config file in Silverlight application.
	/// </summary>
	/// <remarks>The App.config file is expected to reside in the root directory of the project.</remarks>
	public static class ConfigurationManager
	{
		static ConfigurationManager()
		{
			AppSettings = new Dictionary<string, string>();
			ReadSettings(/*Assembly.GetCallingAssembly().FullName*/);
		}

		public static IDictionary<string, string> AppSettings { get; set; }

		static void ReadSettings(/*string assemblyFullName*/)
		{
			XElement rootElement;
			try
			{
				rootElement = XElement.Load("app.config");
			}
			catch (XmlException ex)
			{
				Debug.WriteLine("Unable to get app.config file. " + ex);
				return;
			}

			foreach (XElement element in rootElement.Descendants("appSettings").DescendantNodes())
			{
				AppSettings.Add(element.Attribute("key").Value, element.Attribute("value").Value);
			}
		}
	}
}